<input type="hidden" name='url' id='url' value="<?php echo $this->Html->url( '/', true ); ?>">
<section class="content-header">
	<h1>Mediciones<small>Listado</small></h1>
	<ol class="breadcrumb">

		<li>
      <?php echo $this->Html->link(
        $this->Html->tag('i', '', array('class' => 'fa fa-dashboard ')) . "Inicio",'/',   
        array('class' => '', 'escape' => false)
        ); 		
      ?> 
		</li>		
		<li class="active">Mediciones</li>
	</ol>
</section>

<section class="content">
  <div class="row margin">
    <div class="col-md-6"> 
      <div class="btn-group">
        <?php echo $this->Html->link(__('Nuevo', true), array('controller' => 'measures', 'action' => 'add' ),array('class'=>'btn btn-info btn-flat')); ?> 
        <button class='btn btn-info btn-flat' id='edit_bt' >Editar</button>
        <button class='btn btn-info btn-flat' id='delete_bt'>Eliminar</button>
      </div>
    </div> 
    <div class="hidden col-md-6">
      <div class="input-group">
      <input class="form-control" type="text">
      <span class="input-group-btn">
      <button class="btn btn-info btn-flat" type="button">Go!</button>
      </span>
      </div>
    </div>
  </div>
	<div class="row">
   	<div class="col-md-12">  
      
   		<div class="box">
       <table class="table table-bordered table-hover">
       		<thead>
       			<tr>
              <th>-</th>
              <th> <?php echo $this->Paginator->sort('Periods.year', 'Año'); ?></th>
              <th> <?php echo $this->Paginator->sort('Periods.title', 'Periodo'); ?></th>
              <th> <?php echo $this->Paginator->sort('Services.name', 'Servicio'); ?></th>
              <th> <?php echo $this->Paginator->sort('Members.lastname', 'Socio'); ?></th>
              <th> <?php echo $this->Paginator->sort('Measures.control_date', 'Ultima Medicíon'); ?></th>
              <th> <?php echo $this->Paginator->sort('Measures.value', 'Valor'); ?></th>              
       			</tr>
       		</thead>
        	<tbody>

            <?php foreach ($data as $item):?>
              <tr>
                <td><input type="checkbox"  name="data_id[]" value="<?php echo $item['Measures']['id']?>"></td>
                <td><?php echo $item['Periods']['year']?></td>                    
                <td><?php echo $item['Periods']['title']?></td>                    
                <td><?php echo $item['Services']['name']?></td>
                <td><?php echo $item['Members']['lastname'].' '.$item['Members']['firstname']?></td>
                <td><?php echo $item['Measures']['control_date']?></td>
                <td><?php echo $item['Measures']['value']?></td>
                
              </tr>
            <?php endforeach;?>
        	</tbody>
           
        </table>
        <ul class="pagination">
          <li><?php echo $this->Paginator->first('<i class="fa fa-step-backwards"></i>&nbsp;', array('class'=>'disabled', 'escape'=>false)); ?></li>
          <li><?php echo $this->Paginator->prev('<i class="fa fa-backward"></i>&nbsp;', array('escape'=>false)) ;?></li>
          <li><?php echo $this->Paginator->numbers(array('separator'=>'')); ;?> </li>
          <li><?php echo $this->Paginator->next('<i class="fa fa-forward"></i>&nbsp;', array('escape'=>false)) ;?></li><li><?php echo $this->Paginator->last('<i class="fa fa-step-forward"></i>&nbsp;', array('class'=>'disabled','escape'=>false)); ?></li>       
        </ul>     
    	</div><!-- /.box -->
    </div>
  </div>
</section>

<script type="text/javascript">
  function get_check_id(){
    var result=0;
    $('input[name=data_id\\[\\]]').each(function() {
        if( $(this).is(":checked")){
            var user_id = $(this).val();             
            result =  user_id;
        }
    });
    return result;
  }
  $(function(){
    var url=$("#url").val();
    $("#edit_bt").click(function(){
      chck_id= get_check_id();
      redirect_url=url+"periods/edit/"+chck_id
      window.location.replace(redirect_url);
      //console.debug("THES: %o",redirect_url);
      return false;
    });

    $("#delete_bt").click(function(){
      chck_id= get_check_id();
      redirect_url=url+"members/delete/"+chck_id
      window.location.replace(redirect_url);
      //console.debug("THES: %o",redirect_url);
      return false;
    });
  });
</script>